// index.js
Component({
    options: {
        addGlobalClass: true
    },
    relations: {
        './ui-grid/index': {
            type: 'parent', // 关联的目标节点应为父节点
            linked: function(target) {
                // 每次被插入到custom-ul时执行，target是custom-ul节点实例对象，触发在attached生命周期之后
                this.setData({
                    childRef: {
                        child: this.data.childRef.child.push(target),
                        num: this.data.childRef.num + 1
                    }
                })
            },
            linkChanged: function(target) {
                // 每次被移动后执行，target是custom-ul节点实例对象，触发在moved生命周期之后
            },
            unlinked: function(target) {
                // 每次被移除时执行，target是custom-ul节点实例对象，触发在detached生命周期之后
                this.setData({
                    childRef: {
                        child: this.data.childRef.child.splice(this.data.childRef.child.indexOf(target), 1),
                        num: this.data.childRef.num - 1
                    }
                })
            }
        }
    },
    /**
     * 组件的属性列表
     */
    properties: {
        square: {
            type: Boolean,
            value: false
        },
        extClass: {
            type: String,
            value: ''
        },
        border: {
            type: Boolean,
            value: false
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        childRef: {
            child: [],
            num: 0,
        }
    },
    observers: {
        childRef: function(val) {
            console.log( val );
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {

    }
})